package controller;

import com.jfinal.core.Controller;
import com.jfinal.kit.LogKit;
import com.jfinal.plugin.activerecord.Db;
import model.Student;
import model.User;

import java.util.List;

/**
 * Created by Administrator on 2018/4/18 0018.
 */
public class StudentController extends Controller {


    public void save() {
        String name = getPara("user_name");
        Integer id = getParaToInt("id");
        String nickname = getPara("user_nickname");
        String email = getPara("user_email");
        //System.out.println(name);
        //System.out.println(id);
        //System.out.println(nickname);
        //System.out.println(email);
        boolean success = false; //更新成功的标志变量
        try {
            Db.update("UPDATE t_user SET nickname = ?,email = ? WHERE id = ?",nickname,email, id);
            success = true;
        } catch (Exception e) {
            LogKit.error("修改信息失败，原因：" + e.getMessage());
        }
        String message = success ? "修改信息成功" : "修改信息失败";
        renderHtml(message + "<br><a href='/main'>返回主页</a>");
    }


    public void list() {
        String user_id = getPara("user_id");
        List<User> users = User.dao.find("SELECT * FROM t_user WHERE id = ?",user_id);
        setAttr("users", users);
        renderFreeMarker("student-list.ftl");
    }

}
